/********************************************
 
     This do-file takes cleaned worker
     attitudes data and runs regressions.
 
********************************************/

clear all
set more off
set segmentsize 3g


*-------------------------------------------------------------
*                        Switches                            *
*-------------------------------------------------------------
local main_regressions          1 /* Main Regressions */
local RI_Test                   1 /* RI Inference  */
local line_clustering           1 /* Clustering standard errors at the line-team level */
*-------------------------------------------------------------
* Main Regressions
*-------------------------------------------------------------
if `main_regressions' == 1 {
    
    * Load Data
    use "$Data/Final/worker_attitudes.dta", clear
    
    * Keep only Hindus
    keep if religion == 1
    
    * Define a list of dependent variables and their corresponding additional variables
    local depvars orders_rel comm_rel workp
    local additional_vars_orders_rel "mixedXLD mixedXHD orders_relb orders_relb_missing"
    local additional_vars_comm_rel "mixedXLD mixedXHD comm_relb comm_relb_missing"
    local additional_vars_workp "mixedXLD mixedXHD"
    
    * Run Regressions and Store Estimates
    foreach var in orders_rel comm_rel workp {
        if "`var'" == "orders_rel" {
            areg `var' mixed orders_relb orders_relb_missing i.skill, absorb(line_s) cluster(line_sec_team)
            eststo A1
            local obs1 = e(N)
            su orders_rel if e(sample) & orders_relb_missing == 0
            local meanA = string(round(r(mean), .01))
			local r1 = string(round(e(r2_a), 0.001), "%9.3f")
            
            areg `var' mixedXLD mixedXHD orders_relb orders_relb_missing i.skill, absorb(line_s) cluster(line_sec_team)
            eststo A2
            local obs2 = e(N)
			local r2 = string(round(e(r2_a), 0.001), "%9.3f")
            test mixedXLD = mixedXHD
            local p1 = string(round(r(p), .001))
        }
        else if "`var'" == "comm_rel" {
            areg `var' mixed comm_relb comm_relb_missing i.skill, absorb(line_s) cluster(line_sec_team)
            eststo A3
            local obs3 = e(N)
			local r3 = string(round(e(r2_a), 0.001), "%9.3f")
            su comm_rel if e(sample) & comm_relb_missing == 0
            local meanB = string(round(r(mean), .01))
            
            areg `var' mixedXLD mixedXHD comm_relb comm_relb_missing i.skill, absorb(line_s) cluster(line_sec_team)
            eststo A4
            local obs4 = e(N)
			local r4 = string(round(e(r2_a), 0.001), "%9.3f")
            test mixedXLD = mixedXHD
            local p2 = string(round(r(p), .001))
        }
        else if "`var'" == "workp" {
            areg `var' mixed i.skill, absorb(line_s) cluster(line_sec_team)
            eststo A5
            local obs5 = e(N)
			local r5 = string(round(e(r2_a), 0.001), "%9.3f")
            su workp if e(sample) & mixed == 0
            local meanC = string(round(r(mean), .01))
            
            areg `var' mixedXLD mixedXHD i.skill, absorb(line_s) cluster(line_sec_team)
            eststo A6
            local obs6 = e(N)
			local r6 = string(round(e(r2_a), 0.001), "%9.3f")
            test mixedXLD = mixedXHD
            local p3 = string(round(r(p), .001))
        }
    }
    
    * Export Results to LaTeX
    estout A1 A2 A3 A4 A5 A6 using "$Output/Tables/tables_prefmain", ///
        style(tex) replace ///
        keep(mixed mixedXLD mixedXHD) ///
        cells(b(star fmt(%9.4f)) se(par)) ///
        nolabel collabels(none) mlabels(none) ///
        starlevels(* 0.10 ** 0.05 *** 0.01) ///
        varlabels(mixed "Mixed" ///
            mixedXLD "Mixed $\times$ LD" ///
            mixedXHD "Mixed $\times$ HD")
    
    * Prepare LaTeX Footnotes
    local tex "\hline"
    local tex "`tex' p(Mixed $\times$ HD = Mixed $\times$ LD) &  & `p1' &  & `p2' & & `p3' \\"
    local tex "`tex' Mean Dep. Var & `meanA' & `meanA' & `meanB' & `meanB' & `meanC' & `meanC' \\"
    local tex "`tex' Worker Skill F.E. & Yes & Yes & Yes & Yes & Yes & Yes \\"
    local tex "`tex' Baseline controls & Yes & Yes & Yes & Yes & Yes & Yes \\"
    local tex "`tex' Line $\times$ Section Effects & Yes & Yes & Yes & Yes & Yes & Yes \\"
    local tex "`tex' Observations & `obs1' & `obs2' & `obs3' & `obs4' & `obs5' & `obs6' \\"
	local tex "`tex' Adj. $ R^2$ & `r1' & `r2' & `r3' & `r4' & `r5' & `r6' \\"
    local tex "`tex' \multicolumn{7}{p{8cm}}{\tiny \textit{Notes:} Standard errors clustered at line-section-team level. "
    local tex "`tex' Mixed is a dummy variable coded 1 if the line-section-level team is religiously mixed. "
    local tex "`tex' *** p<0.01, ** p<0.05, * p<0.1.} \\ \end{tabular} }"
    
    * Add Footnotes to LaTeX Table
    esttab A1 A2 A3 A4 A5 A6 using "$Output/Tables/tables_prefmaina", ///
        style(tex) replace booktabs ///
        d(*) nolabel collabels(none) noobs ///
        postfoot("`tex'") nonum ///
        mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)") ///
        mgroups("Taking Orders" "Communicating" "Co-working", ///
            pattern(1 0 1 0 1 0) ///
            prefix(\multicolumn{@span}{c}{) suffix(}) ///
            span erepeat(\cmidrule(lr){@span}))
}


	
*-------------------------------------------------------------
* Randomization Inference
*-------------------------------------------------------------

if `RI_Test' == 1{

use "$Data/Final/worker_attitudes.dta", clear


keep if religion == 1


* Create a single variable for treatment for randomization inference.
gen treatment = 0
replace treatment = 1 if mixedXLD == 1
replace treatment = 2 if mixedXHD == 1

* Placeholder for p-values
local pvalues ""

* Loop through each dependent variable
foreach depvar in orders_rel comm_rel workp {

	local modelname = "`depvar'_model"

	local additionalvars = cond("`depvar'"=="orders_rel", "orders_relb orders_relb_missing", cond("`depvar'"=="comm_rel", "comm_relb comm_relb_missing", ""))
    local skillvar = cond("`depvar'"=="workp", "", "i.skill")
	
	****** Regression with Mixed ******
	{
	* Run the regression
    reghdfe `depvar' i.mixed `additionalvars' `skillvar', absorb(line_s) cluster(line_sec_team)

    * Store the regression result
	estimates store `modelname'_mixed
	
	* Extract coefficients and standard errors, then round to three decimal places
	local mixed_coef_`modelname' = string(round(e(b)[1,"1.mixed"], 0.001), "%9.3f")
	
	local obs`modelname'_mixed = e(N)
	su `depvar' if e(sample) == 1
	local mean`modelname'_mixed = string(round(r(mean), 0.01), "%9.2f")
    
	* Calculate p-values and append significance stars
	local mixed_t_`modelname' = e(b)[1,"1.mixed"]/sqrt(e(V)[2,2])
	local mixed_pval_`modelname' = string(round(2*ttail(e(df_r),abs(`mixed_t_`modelname'')), 0.001), "%9.3f")
	local mixed_stars_`modelname' = cond(`mixed_pval_`modelname'' < 0.01, "***", cond(`mixed_pval_`modelname'' < 0.05, "**", cond(`mixed_pval_`modelname'' < 0.10, "*", "")))

	* Combine coefficients and stars
	local mixed_result_`modelname' = "`mixed_coef_`modelname''`mixed_stars_`modelname''"

    * Run ritest 
    ritest mixed _b[1.mixed],  samplingsourcefile("$Data/Original/Randomized_Teams_RI.dta")  samplingmatchvar(_id) reps(2000) nodots: ///
    reghdfe `depvar' i.mixed `additionalvars' `skillvar', absorb(line_s) cluster(line_sec_team)
	
	local mixed_ri_`modelname' = string(round(el(r(p), 1, 1), 0.001), "%9.3f")
	}
	
	****** Regression with Mixed Interaction ******
    {
	* Run the regression
    reghdfe `depvar' i.treatment `additionalvars' `skillvar', absorb(line_s) cluster(line_sec_team)
	
	* Store the regression result
    estimates store `modelname'
	
	* Extract coefficients and standard errors, then round to three decimal places
	local mixedXLD_coef_`modelname' = string(round(e(b)[1,"1.treatment"], 0.001), "%9.3f")
	local mixedXHD_coef_`modelname' = string(round(e(b)[1,"2.treatment"], 0.001), "%9.3f")
	local obs`modelname' = e(N)

	su `depvar' if e(sample) == 1
	local mean`modelname' = string(round(r(mean), 0.01), "%9.2f")
    
	* Calculate p-values and append significance stars
	local mixedXLD_t_`modelname' = e(b)[1,"1.treatment"]/sqrt(e(V)[2,2])
	local mixedXLD_pval_`modelname' = string(round(2*ttail(e(df_r),abs(`mixedXLD_t_`modelname'')), 0.001), "%9.3f")
	local mixedXLD_stars_`modelname' = cond(`mixedXLD_pval_`modelname'' < 0.01, "***", cond(`mixedXLD_pval_`modelname'' < 0.05, "**", cond(`mixedXLD_pval_`modelname'' < 0.10, "*", "")))
	local mixedXHD_t_`modelname' = e(b)[1,"2.treatment"]/sqrt(e(V)[3,3])
	local mixedXHD_pval_`modelname' = string(round(2*ttail(e(df_r),abs(`mixedXHD_t_`modelname'')), 0.001), "%9.3f")
	local mixedXHD_stars_`modelname' = cond(`mixedXHD_pval_`modelname'' < 0.01, "***", cond(`mixedXHD_pval_`modelname'' < 0.05, "**", cond(`mixedXHD_pval_`modelname'' < 0.10, "*", "")))

	* Combine coefficients and stars
	local mixedXLD_result_`depvar' = "`mixedXLD_coef_`modelname''`mixedXLD_stars_`modelname''"
	local mixedXHD_result_`depvar' = "`mixedXHD_coef_`modelname''`mixedXHD_stars_`modelname''"
		
    * Run ritest (simplified command for demonstration)
    ritest treatment _b[1.treatment] _b[2.treatment],  samplingsourcefile("$Data/Original/Randomized_Teams_RI.dta")  samplingmatchvar(_id) reps(2000) nodots: ///
    reghdfe `depvar' i.treatment `additionalvars' `skillvar', absorb(line_s) cluster(line_sec_team)
    
	local mixedXLD_ri_`modelname' = string(round(el(r(p), 1, 1), 0.001), "%9.3f")
	local mixedXHD_ri_`modelname' = string(round(el(r(p), 1, 2), 0.001), "%9.3f")

	}
}

* Note: This assumes `ritest` successfully stores p-value in r(p) after each run
* Replace `ritest` command with your actual ritest setup

local models "orders_rel_model_mixed orders_rel_model comm_rel_model_mixed comm_rel_model workp_model_mixed workp_model"

* Open a .tex file to store the results
file open results using $Output/Tables/tables_worker_attitudes_ritest_alternative.tex, write replace

* Write the results to the .tex file
file write results "Mixed & `mixed_result_orders_rel_model' &	& `mixed_result_comm_rel_model' &	& `mixed_result_workp_model' &	 \\" _n
file write results "	& (`mixed_pval_orders_rel_model') &	& (`mixed_pval_comm_rel_model') &	& (`mixed_pval_workp_model') &	 \\" _n
file write results "	& [`mixed_ri_orders_rel_model'] &	& [`mixed_ri_comm_rel_model'] &	& [`mixed_ri_workp_model'] &	 \\" _n
file write results "Mixed $\times$ LD &	& `mixedXLD_result_orders_rel' &	& `mixedXLD_result_comm_rel' &	& `mixedXLD_result_workp'  \\" _n
file write results "	&	& (`mixedXLD_pval_orders_rel_model') &	& (`mixedXLD_pval_comm_rel_model') &	& (`mixedXLD_pval_workp_model')  \\" _n
file write results "	&	& [`mixedXLD_ri_orders_rel_model'] &	& [`mixedXLD_ri_comm_rel_model'] &	& [`mixedXLD_ri_workp_model'] \\" _n
file write results "Mixed $\times$ HD &	& `mixedXHD_result_orders_rel' &	& `mixedXHD_result_comm_rel' &	& `mixedXHD_result_workp'  \\" _n
file write results "	&	& (`mixedXHD_pval_orders_rel_model') &	& (`mixedXHD_pval_comm_rel_model') &	& (`mixedXHD_pval_workp_model')  \\" _n
file write results "	&	& [`mixedXHD_ri_orders_rel_model'] &	& [`mixedXHD_ri_comm_rel_model'] &	& [`mixedXHD_ri_workp_model'] \\" _n

file close results


local tex " \\ \hline"
local tex "`tex' Worker Skill F.E. & Yes & Yes & Yes & Yes & Yes & Yes \\"
local tex "`tex' Line $\times$ Section F.E. & Yes & Yes & Yes & Yes & Yes & Yes \\"
local tex "`tex' Mean Dep. Var & `meanorders_rel_model_mixed' & `meanorders_rel_model' & `meancomm_rel_model_mixed' & `meancomm_rel_model' & `meanworkp_model_mixed' & `meanworkp_model' \\"
local tex "`tex' N & `obsorders_rel_model_mixed' & `obsorders_rel_model' & `obscomm_rel_model_mixed' & `obscomm_rel_model' & `obsworkp_model_mixed' & `obsworkp_model' \\"
local tex "`tex' \multicolumn{7}{p{10cm}}{\tiny \textit{Notes:} Standard errors clustered at line-section-team level."
local tex "`tex' P-values are reported in parentheses."
local tex "`tex' Mixed  is  a  dummy  variable  coded  1  if  the  line-section-level  team  is  religiously mixed." 
local tex "`tex' *** p<0.01, ** p<0.05, * p<0.1.} \\ \end{tabular} }"

esttab `models' using "$Output/Tables/tables_worker_attitudes_ritest_alternativea.tex", style(tex) replace booktabs ///
	d(*) nolabel noobs postfoot("`tex'") nonum ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" )
	
}


	
*-------------------------------------------------------------
* Line-team level clustering
*-------------------------------------------------------------

if `line_clustering' == 1{

* Load Data
use "$Data/Final/worker_attitudes.dta", clear

* Keep only Hindus
keep if religion == 1
egen line_team = group(Line Team)


* Main Table (Treatment Effect on Preferences) Table 7 in the paper
areg orders_rel mixed orders_relb orders_relb_missing i.skill, absorb(line_s) cluster(line_team)
eststo A1
local A1_pval = string(round(r(table)[4,1], 0.001), "%9.3f")
local A1_coef = string(round(r(table)[1,1], 0.001), "%9.3f")
local A1_stars = cond(`A1_pval' < 0.01, "***", cond(`A1_pval' < 0.05, "**", cond(`A1_pval' < 0.10, "*", "")))
local A1_result = "`A1_coef'`A1_stars'"
 
local obs1 = e(N)
su orders_relb if e(sample) == 1 & orders_relb_missing == 0
local meanA = string(round(r(mean), .01))

wildbootstrap areg orders_rel mixed orders_relb orders_relb_missing i.skill, absorb(line_s) cluster(line_team) rseed(12345) coefficients(mixed)
local A1_pval_wbs = string(round(r(table)[3,1], 0.001), "%9.3f")
 
areg orders_rel mixedXLD mixedXHD orders_relb orders_relb_missing i.skill, absorb(line_s) cluster(line_team)
eststo A2
local LD_A2_pval = string(round(r(table)[4,1], 0.001), "%9.3f")
local LD_A2_coef = string(round(r(table)[1,1], 0.001), "%9.3f")
local LD_A2_stars = cond(`LD_A2_pval' < 0.01, "***", cond(`LD_A2_pval' < 0.05, "**", cond(`LD_A2_pval' < 0.10, "*", "")))
local LD_A2_result = "`LD_A2_coef'`LD_A2_stars'"

local HD_A2_pval = string(round(r(table)[4,2], 0.001), "%9.3f")
local HD_A2_coef = string(round(r(table)[1,2], 0.001), "%9.3f")
local HD_A2_stars = cond(`HD_A2_pval' < 0.01, "***", cond(`HD_A2_pval' < 0.05, "**", cond(`HD_A2_pval' < 0.10, "*", "")))
local HD_A2_result = "`HD_A2_coef'`HD_A2_stars'"

local obs2 = e(N)
test mixedXLD = mixedXHD
local p1 = string(round(r(p), .001))

wildbootstrap areg orders_rel mixedXLD mixedXHD orders_relb orders_relb_missing i.skill, absorb(line_s) cluster(line_team) rseed(12391) coefficients(mixedXLD mixedXHD)
local LD_A2_pval_wbs = string(round(r(table)[3,1], 0.001), "%9.3f")
local HD_A2_pval_wbs = string(round(r(table)[3,2], 0.001), "%9.3f")
 

areg comm_rel mixed comm_relb comm_relb_missing i.skill, absorb(line_s) cluster( line_team)
eststo A3
local A3_pval = string(round(r(table)[4,1], 0.001), "%9.3f")
local A3_coef = string(round(r(table)[1,1], 0.001), "%9.3f")
local A3_stars = cond(`A3_pval' < 0.01, "***", cond(`A3_pval' < 0.05, "**", cond(`A3_pval' < 0.10, "*", "")))
local A3_result = "`A3_coef'`A3_stars'"

local obs3 = e(N)
su comm_relb if e(sample) == 1 & comm_relb_missing == 0
local meanB = string(round(r(mean), .01))

wildbootstrap areg comm_rel mixed comm_relb comm_relb_missing i.skill, absorb(line_s) cluster(line_team) rseed(12345)  coefficients(mixed)
local A3_pval_wbs = string(round(r(table)[3,1], 0.001), "%9.3f")
 
areg comm_rel mixedXLD mixedXHD comm_relb orders_relb_missing i.skill, absorb(line_s) cluster(line_team)
eststo A4
local LD_A4_pval = string(round(r(table)[4,1], 0.001), "%9.3f")
local LD_A4_coef = string(round(r(table)[1,1], 0.001), "%9.3f")
local LD_A4_stars = cond(`LD_A4_pval' < 0.01, "***", cond(`LD_A4_pval' < 0.05, "**", cond(`LD_A4_pval' < 0.10, "*", "")))
local LD_A4_result = "`LD_A4_coef'`LD_A4_stars'"
 
local HD_A4_pval = string(round(r(table)[4,2], 0.001), "%9.3f")
local HD_A4_coef = string(round(r(table)[1,2], 0.001), "%9.3f")
local HD_A4_stars = cond(`HD_A4_pval' < 0.01, "***", cond(`HD_A4_pval' < 0.05, "**", cond(`HD_A4_pval' < 0.10, "*", "")))
local HD_A4_result = "`HD_A4_coef'`HD_A4_stars'"
 
local obs4 = e(N)
test mixedXLD = mixedXHD
local p2 = string(round(r(p), .001))

wildbootstrap areg comm_rel mixedXLD mixedXHD comm_relb comm_relb_missing i.skill, absorb(line_s) cluster(line_team) rseed(12345)  coefficients(mixedXLD mixedXHD)
local LD_A4_pval_wbs = string(round(r(table)[3,1], 0.001), "%9.3f")
local HD_A4_pval_wbs = string(round(r(table)[3,2], 0.001), "%9.3f")


areg workp mixed i.skill, absorb(line_s) cluster(line_team)
eststo A5
local A5_pval = string(round(r(table)[4,1], 0.001), "%9.3f")
local A5_coef = string(round(r(table)[1,1], 0.001), "%9.3f")
local A5_stars = cond(`A5_pval' < 0.01, "***", cond(`A5_pval' < 0.05, "**", cond(`A5_pval' < 0.10, "*", "")))
local A5_result = "`A5_coef'`A5_stars'"

local obs5 = e(N)
su workp if e(sample) == 1 & mixed == 0
local meanC = string(round(r(mean), .01))

wildbootstrap areg workp mixed i.skill, absorb(line_s) cluster(line_team) rseed(12345) coefficients(mixed)
local A5_pval_wbs = string(round(r(table)[3,1], 0.001), "%9.3f")


areg workp mixedXLD mixedXHD i.skill, absorb(line_s) cluster(line_team)
eststo A6
local LD_A6_pval = string(round(r(table)[4,1], 0.001), "%9.3f")
local LD_A6_coef = string(round(r(table)[1,1], 0.001), "%9.3f")
local LD_A6_stars = cond(`LD_A6_pval' < 0.01, "***", cond(`LD_A6_pval' < 0.05, "**", cond(`LD_A6_pval' < 0.10, "*", "")))
local LD_A6_result = "`LD_A6_coef'`LD_A6_stars'"
 
local HD_A6_pval = string(round(r(table)[4,2], 0.001), "%9.3f")
local HD_A6_coef = string(round(r(table)[1,2], 0.001), "%9.3f")
local HD_A6_stars = cond(`HD_A6_pval' < 0.01, "***", cond(`HD_A6_pval' < 0.05, "**", cond(`HD_A6_pval' < 0.10, "*", "")))
local HD_A6_result = "`HD_A6_coef'`HD_A6_stars'"
 
local obs6 = e(N)
test mixedXLD = mixedXHD
local p3 = string(round(r(p), .001))

wildbootstrap areg workp mixedXLD mixedXHD i.skill, absorb(line_s) cluster(line_team) rseed(99312) coefficients(mixedXLD mixedXHD)
local LD_A6_pval_wbs = string(round(r(table)[3,1], 0.001), "%9.3f")
local HD_A6_pval_wbs = string(round(r(table)[3,2], 0.001), "%9.3f")


* Open a .tex file to store the results
file open results using $Output/Tables/tables_pref_lineclustering, write replace

* Write the results to the .tex file
file write results "Mixed & `A1_result' &  & `A3_result' &  & `A5_result' & \\" _n
file write results "  & (`A1_pval') &  & (`A3_pval') &  & (`A5_pval') & \\" _n
file write results "  & [`A1_pval_wbs'] &  & [`A3_pval_wbs'] &  & [`A5_pval_wbs'] & \\" _n
file write results "Mixed $\times$ LD &  & `LD_A2_result' &  & `LD_A4_result' &  & `LD_A6_result' \\" _n
file write results "  &  & (`LD_A2_pval') &  & (`LD_A4_pval') &  & (`LD_A6_pval')  \\" _n
file write results "  &  & [`LD_A2_pval_wbs'] &  & [`LD_A4_pval_wbs'] &  & [`LD_A6_pval_wbs'] \\" _n
file write results "Mixed $\times$ HD &  & `HD_A2_result' &  & `HD_A4_result' &  & `HD_A6_result'  \\" _n
file write results "  &  & (`HD_A2_pval') &  & (`HD_A4_pval') &  & (`HD_A6_pval')  \\" _n
file write results "  &  & [`HD_A2_pval_wbs'] &  & [`HD_A4_pval_wbs'] &  & [`HD_A6_pval_wbs'] \\" _n
file close results
				
				
local tex " \\ \hline"
local tex "`tex' p(Mixed $\times$ HD = Mixed $\times$ LD) &  & `p1' &  & `p2' & & `p3'  \\"
local tex "`tex' Worker Skill F.E. & Yes & Yes & Yes & Yes & Yes & Yes \\"
local tex "`tex' Line $\times$ Section F.E. & Yes & Yes & Yes & Yes & Yes & Yes \\"
local tex "`tex' Mean Dep Var. & `meanA' & `meanA' & `meanB' & `meanB' & `meanC' & `meanC'   \\"
local tex "`tex' N & `obs1' & `obs2' & `obs3' & `obs4'  & `obs5' & `obs6'   \\"
local tex "`tex' \multicolumn{7}{p{8cm}}{\tiny \textit{Notes:} Standard errors clustered at line-section-team level."
local tex "`tex' Mixed  is  a  dummy  variable  coded  1  if  the  line-section-level  team  is  religiously mixed." 
local tex "`tex' *** p<0.01, ** p<0.05, * p<0.1.} \\ \end{tabular} }"
	
esttab A1 A2 A3 A4 A5 A6 using "$Output/Tables/tables_pref_lineclusteringa", style(tex) replace booktabs ///
	d(*) nolabel collabels(none) noobs postfoot("`tex'") nonum ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" ) ///
	mgroups("Taking Orders" "Communicating" "Co-working", pattern(1 0 1 0 1 0) ///
	prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	
}
